//
//  HMQuestionAppend.swift
//  HealthMonitoring
//
//  Created by 珠海正杰 on 2018/9/17.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import SwiftyJSON

/// 添加按钮 ++
class HMQuestionAppend: HMTableViewCell {
    public var cellHeight: CGFloat = 0.0
    let icon = UIImageView()
    let titleLable = UILabel()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    class func cell(json: JSON, tableView: UITableView, cellForRowAt indexPath: IndexPath) -> HMQuestionAppend {
        let identifier = "HMQuestionAppend"
        var cell: HMQuestionAppend? = tableView.dequeueReusableCell(withIdentifier: identifier) as? HMQuestionAppend
        if cell == nil {
            cell = HMQuestionAppend.init(style: .default, reuseIdentifier: identifier)
        }
        cell?.selectionStyle = UITableViewCellSelectionStyle.none
        return cell!
    }
    
    override func setupViews(view: UIView) {
        view.addSubview(icon)
        view.addSubview(titleLable)

        icon.topAlign(view: view, predicate: "10")
        icon.centerXAlign(view: view)
        icon.heightConstrain(predicate: "50")
        icon.widthConstrain(predicate: "50")

        titleLable.topVertically(view: icon, predicate: "10")
        titleLable.centerXAlign(view: view)
        titleLable.textColor = configure.shareConfigure.HMColor2
        cellHeight = 100.0
    }
    
    override func setJson(json: JSON) {
        self.icon.image = UIImage.init(named: json["icon"].stringValue)
        self.titleLable.text = json["text"].stringValue
    }
}
